package
{
    import flash.display.Sprite;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.text.TextFormat;
    
    import gs.TweenLite;
    import gs.easing.Linear;

    public class GameScore extends Sprite
    {
        private var m_label : TextField;
        
        public var m_score : Number = 0;
                
        public function GameScore()
        {
            super();
            configureText();
            updateScoreImm();
        }
        
        private function configureText() : void
        {
            var format : TextFormat = new TextFormat("embedCourierNew", 36, 0xFFFFFF, true);
            
            m_label = new TextField();
            m_label.embedFonts        = true;
            m_label.selectable        = false;
            m_label.mouseEnabled      = false;
            m_label.autoSize          = TextFieldAutoSize.LEFT;
            m_label.defaultTextFormat = format;
            
            this.addChild(m_label);
        }
        
        public function updateScoreImm() : void
        {
            m_score = Globals.score;
            updateScoreLabel();
        }
        
        public function updateScore() : void
        {            
            TweenLite.to(this, 1.0, { m_score : Globals.score, ease : Linear.easeNone, onUpdate : updateScoreLabel });
        }
        
        private function updateScoreLabel() : void
        {
            m_label.text = String(Math.round(m_score));            
        }
    }
}